Repository navigation
Extend the segbuild set from a running node, by deferred re-execution - #402
Merged
Merged
Conversation
The segment set covers #1..#9,420,000 and the chain keeps moving. Rebuilding it from a 131 GB archive every time does not scale, so the node extends it itself. Not by intercepting the trie store, which is what the previous attempt did and what docs/trie-capture-design.md is the retrospective on: interception made a segment a side effect of whatever the node happened to execute, uncles included, so it stopped being the read set of its range -- the only property that makes a segment verifiable. Instead the node counts and decides, and a background task re-executes. Each block's written bytes go to a counter; when enough has accumulated the executed head is recorded as a segment boundary; once the head is --segbuild-lag blocks past that boundary, the range is replayed out of the node's own store and sealed. Blocks are executed twice, which at the tip is about ten seconds of work per eight hours of chain. Either a correct segment or no segment -------------------------------------- A segment that under-covers its range is the worst outcome available, because a missing trie node is indistinguishable at the API from a genuine absence (trie-segments-design.md 6.9d): a consumer reads a wrong answer rather than an error. Two things make that unreachable rather than unlikely. Every state root is verified against its header as the range replays. And the segment is built under `.building-A-B`, which no reader parses as a segment, and renamed only after the replay reaches its end -- so the mismatch path, the missing-node path, a cancel and a SIGKILL all leave the same thing behind. The rename is the commit. The collector has to be told, and a bound alone is not enough ------------------------------------------------------------ A pending range reads historical state out of a garbage-collected store, so something has to keep it. An earlier draft of the design argued it was kept anyway, by lag < burial_depth. That argument is wrong, and this is worth being explicit about because it reads plausibly: the collection root sits at head - 4,000 while a segment is ~90,000 blocks, so the root sits *inside* the pending range, not below it. A node written at A+5 and dead by A+9 is reachable from no state at all, and a node in the state at A-1 that is superseded at A+100 is not in the state at the collection root either. Both are read by the replay. So retention is arranged, and it takes two halves that each cover what the other cannot: - a *bound* at A-1 keeps what blocks at or after A wrote, including nodes created and destroyed inside the range, which no state at either end reaches; a pin cannot express that, because it keeps reachability; - a *pin* on the state root at A-1 keeps the seed trie, which the bound cannot keep, because those nodes were written below it. Together they are exhaustive: a node read while replaying [A..B] was written either before A -- and if it is still needed it is in the trie at A-1 -- or at or after A. One block number produces both, and EpochTrieStore::collect_bounded takes the floor as min(root_block, every registered bound), the collector's own root being simply the bound it imposes on itself. A held floor is an outcome, not a failure. CollectStats::held_by_bound names it and the cycle returns Ok, because a collection that errored once a minute would bury the failures that matter. A bound that stops advancing past --gc-max-bound-lag is overridden, loudly: an incomplete segment set is a thing to repair later, a node out of disk is not. What happens when it cannot work -------------------------------- A range the collector has already swept beneath is written off into UNCOVERED without being attempted. The test is the store's own watermark (collected_below), not the builder's distance from the head, and the distinction matters: distance says a range lost its protection, which is not the same as having been collected -- nothing is gone until a sweep reaches it, and a range that still has its nodes should still be built. A build that fails for any other reason is retried twice and then written off the same way. UNCOVERED is the set's list of known holes, which the offline tool can fill from an archive; the alternative is a builder that loops on the one range it cannot do while every later range starves. Enabling it needs a current set, and the node refuses at startup otherwise: a directory with no NNN-start-end segment cannot be bootstrapped from here (the pre-fork era needs a baseline), and a gap between the set's end and the executed head cannot be built from a collected store. That is the one place segbuild may stop the node, and only before it serves anything. Nothing else in this path may be fatal. Every lock in segbuild_boundaries is taken poison-tolerantly, so a panic in a builder thread cannot poison a lock and then panic the node's execution path on the next block; the builder's outcomes are an enum the caller logs. Extending the set is a by-product of syncing, and failing to extend it is not a reason to stop following the chain. Verified against the chain, not argued -------------------------------------- crates/execution/tests/segment_build_from_store.rs builds real segments from this node's block store and the archive trie: a range at #9,000,000 verifies every state root and contains the seed node for its own first block, a killed build resumes to the identical segment, the pre-fork era is refused rather than built unverified, and the whole loop -- boundary cut at the executed head, refused inside the lag, built once settled, recorded against the chain's hash, floor released -- runs end to end. That last assertion is the one worth having: build_range could be entirely correct while a built range went on holding the collector's floor for ever, and nothing else would catch it. segbuild_capture.rs is deleted. 471 lines of unused dual-write code implies it is the supported path. Its measurement is kept in the design document: interception cost 1.24x per-block execution after per-block batching, 7.6x without. docs/segbuild-continuous-design.md is the design, including what is still open: whether the builder should stay idle while the node is catching up, which trades segment coverage for sync speed and is a policy decision about a production node rather than a code question. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
CI caught five flags in neither ONE_SHOT nor CONFIGURABLE, which is the drift guard in config_file doing its job: --gc-max-bound-lag and the four --segbuild-* flags were command-line only, so a node started from node.toml could not turn segbuild on at all. The list entry is the smallest part of the fix. [gc] gains max_bound_lag, and a new [segbuild] section carries out, target_mb, lag and seal_mb, each wired through apply_file_config. Listing a flag without that wiring does not pass: `# default: unset` is checked by applying the value shown and finding which Args field moved, so a key that drives nothing is reported as either unwired or wrongly marked. Both example files document all five with their defaults, because one test requires the example to name every option by reflection -- a new Option is a new null until it is documented -- and another requires the reference and light examples to cover the same keys. `out` is the one marked `# default: unset`: unset is how the feature stays off, and the node refuses to start if the directory it names is not a current segment set. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The segment set covers #1..#9,420,000 and the chain keeps moving. This makes the node extend the set itself, by deciding where segments end while it syncs and re-executing each range afterwards — not by intercepting the trie store, which is what the previous attempt did and what
trie-capture-design.mdis the retrospective on.Each block's written bytes go to a counter; when enough has accumulated the executed head is recorded as a boundary; once the head is
--segbuild-lagblocks past it, the range is replayed out of the node's own store and sealed. Blocks are executed twice, which at the tip is about ten seconds of work per eight hours of chain.docs/segbuild-continuous-design.mdis the design in full.Either a correct segment or no segment
A segment that under-covers its range is the worst outcome available: a missing trie node is indistinguishable at the API from a genuine absence (
trie-segments-design.md§6.9d), so a consumer reads a wrong answer rather than an error..building-A-B, which no reader parses as a segment, and renamed only after the replay reaches its end. The mismatch path, the missing-node path, a cancel and aSIGKILLall leave the same thing behind. The rename is the commit.The collector has to be told, and a bound alone is not enough
A pending range reads historical state out of a garbage-collected store. An earlier draft of the design argued it was retained anyway, by
lag < burial_depth. That argument is wrong, and it reads plausibly, so it is worth being explicit: the collection root sits athead - 4,000while a segment is ~90,000 blocks, so the root sits inside the pending range. A node written atA+5and dead byA+9is reachable from no state at all; a node in the state atA-1superseded atA+100is not in the state at the collection root either. Both are read by the replay.So retention is arranged, and it takes two halves that each cover what the other cannot:
A-1Awrote, including nodes created and destroyed inside the rangeroot(A-1)Together they are exhaustive: a node read while replaying
[A..B]was written either beforeA— and if still needed it is in the trie atA-1— or at/afterA. One block number produces both.EpochTrieStore::collect_boundedtakes the floor asmin(root_block, every registered bound), the collector's own root being the bound it imposes on itself.A held floor is an outcome, not a failure:
CollectStats::held_by_boundnames it, reported asheldByBoundoverrsk_collectTrieStatus, and the cycle returnsOk— a collection that errored once a minute would bury the failures that matter. A bound that stops advancing past--gc-max-bound-lagis overridden, loudly.What happens when it cannot work
A range the collector has already swept beneath is written off into
UNCOVEREDwithout being attempted. The test is the store's own watermark (collected_below), not distance from the head: distance says a range lost its protection, which is not the same as having been collected — nothing is gone until a sweep reaches it, and a range that still has its nodes should still be built. Any other failure is retried twice and written off the same way.UNCOVEREDis the set's list of known holes, which the offline tool fills from an archive.Enabling it needs a current set, and the node refuses at startup otherwise — an empty set cannot be bootstrapped from here, and a gap between the set's end and the executed head cannot be built from a collected store. That is the one place segbuild may stop the node, and only before it serves anything. Nothing else in this path may be fatal: every lock in
segbuild_boundariesis poison-tolerant, so a panic in a builder thread cannot panic the node's execution path on the next block.Verified against the chain
crates/execution/tests/segment_build_from_store.rs(--ignored, needs a block store and a trie store) builds real segments from this node's own data:The loop test is the one worth having:
build_rangecould be entirely correct while a built range went on holding the collector's floor for ever, and nothing else would catch it.Unit suites: storage 269, execution 1909, rpc 271, sync 670.
cargo clippy --workspace --all-targetsclean.Also
segbuild_capture.rsis deleted — 471 lines of unused dual-write code implies it is the supported path. Its measurement is kept in the design document: interception cost 1.24× per-block execution after per-block batching, 7.6× without.Still open
Whether the builder should stay idle while the node is catching up. It would free CPU for sync exactly when the node needs it, at the cost of guaranteeing the holes that the write-off rule merely records sooner — a policy decision about a production node rather than a code question. §7.3 has the arithmetic.
🤖 Generated with Claude Code